/*
 * File Name : user.cpp
 * Auther : dream.liuguobiao
 * Create Date : 2010-5-11
 * Last Edit : 2010-5-14
 */

#include "user.h"
#include <vector>

user::user( std::string new_name  )
:name(new_name),next_user(NULL)
{
}

user::user( std::string new_name , int new_ID)
{
 name = new_name; ID = new_ID ; 
}

user::~user(){
  std::vector<group *>::iterator group;
  for(group = groups.begin() ;group < groups.end(); group++){
    (*group)->remove_user(this);
  }
}

std::string *user::get_name(){
  return &name;
}


int user::get_ID(){
 return ID;
}

bool user::set_ID(int new_ID){
  ID = new_ID;
  return 0;
}

std::vector<group *>* user::get_groups(){
  return &groups;
}

bool user::remove_group( group *delete_group ){
  std::vector<group *>::iterator group = groups.begin();
  for(; group < groups.end() ; group ++){
    if( *group == delete_group )
      groups.erase(group);
  }
  return 0;
}

bool user::insert_group( group *insert_group ){
  groups.push_back( insert_group );
  return 0;
}

user *user::get_next_user(){

return next_user;
}


bool user::set_next_user(user *new_user){
  next_user = new_user;
  return 0;
}

std::string *user::get_password(){
  return &password;
}

bool user::set_password( std::string *new_password){
  password = *new_password;
  return 0;
}

